//
//  BaseViewController.swift
//  OMTUIKitSwift
//
//  Created by 昭荣伊 on 2018/12/10.
//

import Foundation

open class BaseViewController: UIViewController {
    
    /// 导航栏
    public lazy var navigationBar: OMTNavigationBar = {
        let navigationBar = OMTNavigationBar()
        return navigationBar
    }()
    
    /// 即将返回
    public var willBackBlock:(() -> Void)?
    
    open override var title: String? {
        didSet {
            self.navigationBar.title = self.title
        }
    }
    
    open override func viewDidLoad() {
        super.viewDidLoad()
        self.automaticallyAdjustsScrollViewInsets = false
        self.navigationController?.isNavigationBarHidden = true
        self.view.backgroundColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
        
        self.setupBaseSubviews()
        self.setupBaseConstraints()
    }
    
    open override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.view.bringSubviewToFront(self.navigationBar)
    }
    
    func setupBaseSubviews() {
        self.navigationBar.didClickLeftButtonBlock = {[weak self] (sender) in
            if let self = self {
                self.backAction()
            }
        }
        self.view.addSubview(self.navigationBar)
    }
    
    func setupBaseConstraints() {
        
    }
    
    // MARK: Public
    public func backAction() {
        if let willBackBlock = self.willBackBlock {
            willBackBlock()
        }
    }
    
    @objc public func excuteWillBackBlock() {
        
    }
}
